home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / analogjoystick / vbrtn.a < prev   
Text File  |  1980-01-07  |  6KB  |  211 lines

  1.  
  2.  
  3. *********************************************************
  4. *                                                       *
  5. * Copyright (c) 1989, David Kinzer, All Rights Reserved *
  6. *                                                       *
  7. * Permission hereby granted to redistribute this        *
  8. * program in unmodified form in a not for profit manner.*
  9. *                                                       *
  10. * Permission hereby granted to use this software freely *
  11. * in programs, commercial or not.                       *
  12. *                                                       *
  13. *********************************************************
  14. *                                                       *
  15. * VBRtn.a                                               *
  16. *                                                       *
  17. * Vertical Blanking Routine for analog joystick support.*
  18. * This routine reads the joyport hardware during every  *
  19. * vertical blanking interrupt and stores the joystick   *
  20. * data for use by the read routine.                     *
  21. *                                                       *
  22. *********************************************************
  23.  
  24.  
  25.  
  26. * The ordering of the buttons is sortof taken from the
  27. * RKM hardware manual (buttons 3 and 4 are not defined
  28. * there) 
  29. *
  30. * when reading from the joyport it is  xxxxxx13xxxxxx24
  31. * where 1 & 2 are obtained directly, 3 is obtained by 1
  32. * eor 3, and 4 is obtained by 2 eor 4.
  33. *
  34. *
  35.  
  36. * Lattice (tm) users need to remove the comment asterisk
  37. * from the following line to make the assembler happy
  38.  
  39. *       csect   text
  40.  
  41.  
  42. regbase equ     $DFF000
  43. joy0dat equ     $00A
  44. pot0dat equ     $012
  45. joy1dat equ     $00C
  46. pot1dat equ     $014
  47.  
  48. WritePotgo equ -$12
  49.  
  50.  
  51. o_U0X       equ     $0          offsets for data passing
  52. o_U0Y       equ     $2           structure
  53. o_U0b1      equ     $4
  54. o_U0b2      equ     $5
  55. o_U0b3      equ     $6
  56. o_U0b4      equ     $7
  57. o_U0eb1     equ     $8
  58. o_U0eb2     equ     $9
  59. o_U0eb3     equ     $a
  60. o_U0eb4     equ     $b
  61.  
  62. o_U1X       equ     $c
  63. o_U1Y       equ     $e
  64. o_U1b1      equ     $10
  65. o_U1b2      equ     $11
  66. o_U1b3      equ     $12
  67. o_U1b4      equ     $13
  68. o_U1eb1     equ     $14
  69. o_U1eb2     equ     $15
  70. o_U1eb3     equ     $16
  71. o_U1eb4     equ     $17
  72.  
  73. o_Potbase   equ     $18 
  74. o_flags     equ     $1c
  75.  
  76.  
  77.  
  78.    xdef     _vbserver
  79.  
  80. * We rely on the data area being pointed to by A1 upon
  81. * entry, which the exec does for us.
  82. *
  83. * We can consider D0, D1, A0, A1, A4, A5 and A6 scratch
  84.  
  85. _vbserver:
  86.  
  87.  
  88.     move.l  #regbase,A0         A0 points to hardware base
  89.  
  90.     btst    #0,o_flags+3(A1)    see if unit 0 open
  91. *                                (btst works on bytes)
  92.     beq     u1                  branch if not
  93.  
  94.     move.w  pot0dat(A0),D0      save pot data
  95.     move.w  D0,D1
  96.     asl.w   #8,D0
  97.     move.w  D0,o_U0X(A1)
  98.     and.w   #$FF00,D1
  99.     move.w  D1,o_U0Y(A1)
  100.  
  101.     move.w  joy0dat(A0),D1      get joystick button
  102. *                                positions
  103.  
  104.     move.b  o_U0b1(A1),D0       do button 1
  105. *                                save previous state
  106.     btst    #9,D1               test to see if pressed
  107.     sne     o_U0b1(A1)          set or clear data element
  108. *                                based on position
  109.     beq.s   u0t1                if not pressed we are done
  110.     tst.b   D0                  was it pressed before?
  111.     bne.s   u0t1                yes, branch
  112.     st      o_U0eb1(A1)         just pressed, set flag
  113. *                                indicating button pressed
  114. u0t1
  115.     move.b  o_U0b2(A1),D0       do button 2
  116.     btst    #2,D1
  117.     sne     o_U0b2(A1)
  118.     beq.s   u0t2
  119.     tst.b   D0
  120.     bne.s   u0t2
  121.     st      o_U0eb2(A1)
  122. u0t2
  123. * The fastest way to do the exclusive or in this case is
  124. * to add 1 to the least significant bit.  If that bit is
  125. * a 1, there will be a carry into the next position.  If
  126. * so, and the next position is a zero, the result will be
  127. * a one.  If the next position is a one, the result is a
  128. * zero.  Obscure, but fast.  Note that this renders all
  129. * other bits useless.  We use a byte add here to prevent
  130. * ruining the button 2 and 4 data in the upper byte.
  131.     add.b   #1,D1               do button 3
  132.     move.b  o_U0b3(A1),D0       
  133.     btst    #1,D1
  134.     sne     o_U0b3(A1)
  135.     beq.s   u0t3
  136.     tst.b   D0
  137.     bne.s   u0t3
  138.     st      o_U0eb3(A1)
  139. u0t3
  140.     add.w   #$100,D1            do button 4
  141.     move.b  o_U0b4(A1),D0       (same eor scheme used)
  142.     btst    #9,D1
  143.     sne     o_U0b4(A1)
  144.     beq.s   u0t4
  145.     tst.b   D0
  146.     bne.s   u0t4
  147.     st      o_U0eb4(A1)
  148. u0t4
  149.  
  150.  
  151.  
  152. u1
  153.     btst    #1,o_flags+3(A1)    see if unit 1 open
  154.     beq     restart
  155.  
  156.     move.w  pot1dat(A0),D0      save pot data
  157.     move.w  D0,D1
  158.     asl.w   #8,D0
  159.     move.w  D0,o_U1X(A1)
  160.     and.w   #$FF00,D1
  161.     move.w  D1,o_U1Y(A1)
  162.  
  163.     move.w  joy1dat(A0),D1      get joystick button
  164. *                                positions
  165.  
  166.     move.b  o_U1b1(A1),D0       do button 1
  167.     btst    #9,D1
  168.     sne     o_U1b1(A1)
  169.     beq.s   u1t1
  170.     tst.b   D0
  171.     bne.s   u1t1
  172.     st      o_U1eb1(A1)
  173. u1t1
  174.     move.b  o_U1b2(A1),D0       do button 2
  175.     btst    #1,D1
  176.     sne     o_U1b2(A1)
  177.     beq.s   u1t2
  178.     tst.b   D0
  179.     bne.s   u1t2
  180.     st      o_U1eb2(A1)
  181. u1t2
  182.     add.b   #1,D1
  183.     move.b  o_U1b4(A1),D0       do button 4
  184.     btst    #1,D1
  185.     sne     o_U1b4(A1)
  186.     beq.s   u1t4
  187.     tst.b   D0
  188.     bne.s   u1t4
  189.     st      o_U1eb4(A1)
  190. u1t4
  191.     add.w   #$100,D1            do button 3
  192.     move.b  o_U1b3(A1),D0       
  193.     btst    #9,D1
  194.     sne     o_U1b3(A1)
  195.     beq.s   u1t3
  196.     tst.b   D0
  197.     bne.s   u1t3
  198.     st      o_U1eb3(A1)
  199. u1t3
  200. restart
  201.     move.l  #1,D0
  202.     move.l  D0,D1
  203.     move.l  o_Potbase(A1),A6        Call WritePotgo
  204.     jsr     WritePotgo(A6)
  205.     move.l  #0,D0
  206.     rts
  207.  
  208.     end
  209.  
  210. * End: VBRtn.a
  211.